import type { Responses } from './types/class'
import { http } from '@/utils/request'

export const getClassesByCurrentUser = (): Promise<Responses['getClassesByCurrentUser']> => http.get('/reading/classes/user')

export const getClassInfoByClassId = (classId: number): Promise<Responses['getClassInfoByClassId']> => http.get(`/reading/classes/${classId}`)

export function createClass(className: string, description: string): Promise<Responses['createClass']> {
  return http.post('/reading/classes', {
    className,
    description,
  })
}

export const joinClass = (classCode: string): Promise<Responses['joinClass']> => http.post('/reading/classes/join', { classCode })

export const getPunchRecordsByClassId = (classId: number): Promise<Responses['getPunchRecordsByClassId']> => http.get(`/reading/classes/${classId}/punch-records`)

export const getMembersByClassId = (classId: number): Promise<Responses['getMembersByClassId']> => http.get(`/reading/classes/${classId}/members`)

export const getStudentsByClassId = (classId: number): Promise<Responses['getMembersByClassId']> => http.get(`/reading/classes/${classId}/students`)

export const deleteClassByClassId = (classId: number): Promise<Responses['deleteClassByClassId']> => http.delete(`/reading/classes/${classId}`)

export function modifyClassNameAndDescByClassId(classId: number, className: string, description: string): Promise<Responses['modifyClassNameAndDescByClassId']> {
  return http.put(`/reading/classes/${classId}`, {
    className,
    description,
  })
}

export const transferClassToMember = (classId: number, userId: number): Promise<Responses['transferClassToMember']> => http.post(`/reading/classes/${classId}/transfer`, { newCreatorId: userId })

export const deleteMemberFromClass = (classId: number, userId: number): Promise<Responses['deleteMemberFromClass']> => http.delete(`/reading/classes/${classId}/members/${userId}`)

export const lockClassByClassId = (classId: number, lock: boolean): Promise<Responses['lockClassByClassId']> => http.put(`/reading/classes/${classId}/lock`, { isLocked: lock })
